package com.example.jasyptdb.util;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *  TODO
 * @author 江
 * @date 2021/9/13 下午 14:44
 */
public class HttpResult extends HashMap<String,Object> {
    private HttpResult() {
        this(HttpStatus.SUCCESS);
    }
    private HttpResult(int code,String msg){
        this.put("status",code);
        this.put("msg",msg);
    }
    private HttpResult(HttpStatus httpStatus){
        this.put("status",httpStatus.getCode());
        this.put("msg",httpStatus.getMsg());
    }


    public HttpResult add(String name,Object value){
        this.put(name,value);
        return this;
    }

    public HttpResult addAll(Object value){
        if(value instanceof Map){
            this.addAll(value);
        }else if(value instanceof List){
            this.put("list",value);
        }
        return this;
    }
    public static HttpResult newSuccess(){
        return new HttpResult();
    }
    public static HttpResult newSuccess(String msg){
        return new HttpResult(HttpStatus.SUCCESS.getCode(),msg);
    }

    public static HttpResult newError(){
        return new HttpResult(HttpStatus.FAIL);
    }
    public static HttpResult newError(String msg){
        return new HttpResult(HttpStatus.FAIL.getCode(),msg);
    }

    public static HttpResult newNoLogin(){
        return new HttpResult(HttpStatus.NO_LOGIN);
    }
    public static HttpResult newNoAuth(){
        return new HttpResult(HttpStatus.AUTH_ERROR);
    }
    public static HttpResult newNoFile(){
        return new HttpResult(HttpStatus.NO_FILE);
    }

}
